package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.result.Result;
import com.sky.service.SearchHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/search")
@Api(tags = "C端-用户搜索历史接口")
public class SearchHistoryController {
    @Autowired
    private SearchHistoryService searchHistoryService;

    /**
     * 用户搜索记录
     * @return
     */
    @GetMapping("/lsit")
    @ApiOperation("用户搜索记录")
    @Cacheable(cacheNames = "userCache",key="#id")
    public Result<List<String>> search(){
        Long id = BaseContext.getCurrentId();

        List<String> strings = searchHistoryService.searchList(id);
        log.info("用户搜索历史记录:{}",strings);
       return Result.success(strings);
    }

    /**
     * 用户搜索
     * @return
     */
    @GetMapping
    @ApiOperation("用户搜索")
    @Cacheable(cacheNames = "userCache",key="#id")
    public Result<List<String>> search(String s ){
        Long id = BaseContext.getCurrentId();
        List<String> strings = searchHistoryService.search(s);
        log.info("用户搜索:{}",strings);
        return Result.success(strings);
    }

}
